package com.baidu.threadPoolExcutor.threadInThreadTest;

public class ThreadTask implements OrderRunnable{
    private Student student;

    public ThreadTask(Student student){
        this.student = student;
    }

    @Override
    public int position(int coreSize) {
        int id = this.student.getId();
        // 根据id和coreSize取模
        int pos = Math.abs(id) % coreSize;
        return pos;
    }

    @Override
    public void run() {
        try {
            doTask(this.student);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 任务主逻辑
     * @param student
     */
    private void doTask(Student student) throws InterruptedException {
        String threadName = Thread.currentThread().getName();
        System.out.println("id : " + student.getId() + "   age : " + student.getAge() + "  由：" + threadName + "线程来处理");
    }
}


